package com.剑指offer;


/*
 * 输入一棵二叉树，求该树的深度。从根结点到叶结点依次经过的结点（含根、叶结点）形成树的一条路径，最长路径的长度为树的深度。
 * * */
public class _38树的深度
{
    public static void main(String[] args)
    {
        TreeNode t1 = new TreeNode(1);
        TreeNode t2 = new TreeNode(2);
        TreeNode t3 = new TreeNode(3);
        TreeNode t4 = new TreeNode(0);
        t1.left = t2;
        t1.right = t3;
        t2.right = t3;
        int i = TreeDepth(t1);
        System.out.println(i);
    }

    public static int TreeDepth(TreeNode root)
    {
        if (root == null)
        {
            return 0;
        }
        int left = TreeDepth(root.left);
        int right = TreeDepth(root.right);

        return (left > right ? (left + 1) : (right + 1));
    }
}

/*
* public class TreeNode
{
    TreeNode left = null;
    TreeNode right = null;
    int val;
    public TreeNode(int val){
        this.val = val;
    }
}
* */